package com.photovoltaic.auth.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.photovoltaic.auth.entity.UserPermission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UserPermissionMapper extends BaseMapper<UserPermission> {
    
    /**
     * 根据用户ID获取该用户的直接权限ID列表
     *
     * @param userId 用户ID
     * @return 该用户的直接权限ID列表
     */
    @Select("SELECT permission_id FROM user_permission WHERE user_id = #{userId}")
    List<Long> getUserDirectPermissions(@Param("userId") Long userId);
    
    /**
     * 根据用户ID删除该用户的所有直接权限
     *
     * @param userId 用户ID
     * @return 影响的行数
     */
    @Delete("DELETE FROM user_permission WHERE user_id = #{userId}")
    int deleteByUserId(@Param("userId") Long userId);
} 